/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.googlecode.datawander.codegenerator;

import java.util.ArrayList;
import java.util.List;
import org.apache.log4j.Logger;

/**
 *
 * @author Marcin Stachniuk
 */
public class GeneratedDatabaseFields {

    private static final Logger logger = Logger.getLogger(GeneratedDatabaseFields.class);

    private List<ForeignKey> foreignKeysList = new ArrayList<ForeignKey>();
    private List<RelationalColumn> relationalColumns = new ArrayList<RelationalColumn>();

    /**
     * Add to table foreign key that referenced to promary key in referencedTable.
     * @param table Table name that add foregin key.
     * @param referencedTable Table name where is primary key.
     * @param nameOfField Name of added field.
     * @param relationalDataType Relational data type.
     * @param objectDataType Object data type.
     * @param referencedObjectFieldName Name of field in referenced object for
     * that is created RelationalFieldFK.
     * @param unique Information about foregin key must be unique.
     */
    public void addRelationalFieldFK(String table, String referencedTable, 
            String nameOfField, String relationalDataType, String objectDataType,
            Class referencedClassName, String referencedObjectFieldName, boolean unique) {

        logger.trace("addRelationalFieldFK(" + table +
                                    ", " + referencedTable + ", " + nameOfField + 
                                    ", " + relationalDataType + ", " + objectDataType +
                                    ", " + referencedClassName +
                                    ", " + referencedObjectFieldName + ", " + unique + ");");

        ForeignKey foreignKey = new ForeignKey();
        foreignKey.setOwnerTable(table);
        foreignKey.setReferencedTableName(referencedTable);
        foreignKey.setName(nameOfField);
        foreignKey.setReferencedTablePrimaryKey(RelationalDatabaseScriptGenerator.PRIMARY_KEY_NAME);
        foreignKey.setRelationalType(relationalDataType);
        foreignKey.setObjectType(objectDataType);
        foreignKey.setReferencedClass(referencedClassName);
        foreignKey.setReferencedObjectFieldName(referencedObjectFieldName);
        foreignKey.setUnique(unique);

        foreignKeysList.add(foreignKey);
    }

    public void addRelationalColumn(String table, String name,
            String relationalType, String objectType) {
        logger.trace("addRelationalColumn(" + table + ", " + name + ", " +
                relationalType + ", " + objectType);

        RelationalColumn relColumn = new RelationalColumn();
        relColumn.setTable(table);
        relColumn.setName(name);
        relColumn.setRelationalType(relationalType);
        relColumn.setObjectType(objectType);

        relationalColumns.add(relColumn);
    }

    public List<ForeignKey> getForeignKeys() {
        return foreignKeysList;
    }

    public List<RelationalColumn> getRelationalColumns() {
        return relationalColumns;
    }
}
